The debounce() operator for Flow discards rapid changes in data. It only emits objects downstream if the upstream Flow has not changed for the supplied period in milliseconds. Also, the last object emitted by the upstream flow is passed downstream if the upstream flow is closed.

The simple form of debounce(), shown here, takes a fixed delay period in milliseconds. In this case, it is 250 milliseconds. While the initial Flow from bouncyBouncy() emits 0, 1, 2, 3, and 4, we only see the latter two. The first three are all replaced by later values faster than 250 milliseconds, so they are skipped. 3 is emitted because of the 400 millisecond delay that follows it, and 4 is emitted because the Flow is closed afterwards.

You can learn more about this in:
Tags:
Run Edit